@extends('../manage.layout')
@section('content')
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            系统管理
            <small>配置列表</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
            <li class="active">Here</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content animated fadeInRight">
        <div class="row">
            <div class="col-md-12">
                <!-- general form elements -->
                <div class="box box-primary">

                    <!-- table start -->
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                                <div class="box-header">
                                    <h3 class="box-title">配置信息</h3>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="config/create" class="btn btn-primary">添加配置信息</a>
                                </div>
                                <!-- /.box-header -->
                                <div class="box-body table-responsive no-padding">
                                    <table class="table table-bordered table-hover table-striped">
                                        <tr>
                                            <th>ID</th>
                                            <th>创建时间</th>
                                            <th>更新时间</th>
                                            <th>权重</th>
                                            <th>网站名称</th>
                                            <th>标题</th>
                                            <th>关键词</th>
                                            <th>状态</th>
                                            <th>操作</th>
                                        </tr>
                                        @foreach($config as $v)
                                            <tr>
                                                <td>{{ $v['id'] }}</td>
                                                <td>{{ $v['create_time'] }}</td>
                                                <td>{{ $v['update_time'] }}</td>
                                                <td>{{ $v['rank'] }}</td>
                                                <td>{{ $v['name'] }}</td>
                                                <td>{{ $v['title'] }}</td>
                                                <td>{{ $v['keyword'] }}</td>
                                                <td>
                                                    @if($v['status'] == 0)<label>已禁用</label>
                                                    @else<label>启用中</label>
                                                    @endif
                                                </td>
                                                <td>
                                                    <a href="config/{{ $v['id'] }}/edit"><span class="label label-primary">更改</span></a>
                                                    @if($v['status'] == 1)
                                                        <a class="btn btn-warning btn-xs" href="javascript:setStatus('{{ $v['id'] }}',0)">禁用<a>
                                                    @elseif($v['status'] == 0)
                                                        <a class="btn btn-success btn-xs" href="javascript:setStatus('{{ $v['id'] }}',1)">启用<a>
                                                    @endif
                                                    <a href="javascript:delSubscribe({{ $v['id'] }})"><span class="label label-danger">删除</span></a>
                                                </td>
                                            </tr>
                                        @endforeach
                                    </table>
                                </div>
                                <!-- /.box-body -->
                            </div>
                            <!-- /.box -->
                        </div>
                    </div>
                    <!-- /.table -->
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
@endsection
@section('script')
    <!--layer-->
    <script src="/plugin/layer-v3.0.3/layer/layer.js"></script>
    <script>
        function delSubscribe(id) {
            layer.confirm('删除不可恢复，是否继续？', {
                btn:['确定','取消'] //按钮
            }, function() {
                $.post("{{ url('manage/config/') }}/"+id,{'_method':'delete','_token':"{{ csrf_token() }}"},function(data){
                    if(data.code==100) {
                        layer.msg(data.msg, {time:1500, icon:6, end:function(){location.reload();}});
                    } else {
                        layer.msg(data.msg, {time:1500, icon:5, end:function(){location.reload();}});
                    }
                });
            }, function() {

            });
        }
        //禁用,启用
        function setStatus(id,status) {
            $.ajax({
                url: '/manage/config/status',
                type: "GET",
                data: {id:id,status:status},
                dataType: "json",
                success: function(res) {
                    console.log(res);
                    if(res.code == 100) {
                        window.location.href=window.location.href;
                        layer.msg(res.msg, {time:1500, icon:6})
                    }
                    else {
                        layer.msg(res.msg, {time:1500, icon:5})
                    }
                },
                error:function(){
                    alert('ERROR');
                }
            });
        }
    </script>
@endsection
